#ifndef KEYRINGTEST_HPP
#define KEYRINGTEST_HPP

//#include <fstream>
#include <cstdlib>
//#include <cstdio>
//#include <string>
#include <cppunit/extensions/HelperMacros.h>
#include "keyring.hpp"

class KeyRingTest : public CppUnit::TestFixture {
  CPPUNIT_TEST_SUITE( KeyRingTest );
  CPPUNIT_TEST( test_KeyRing );
  CPPUNIT_TEST_SUITE_END();
  
public:
  void setUp();
  void tearDown();
  void test_KeyRing();
};

void KeyRingTest::setUp() {}
void KeyRingTest::tearDown() {}
 
void KeyRingTest::test_KeyRing() {

  KeyRing::KeyRing keyRing;
  CPPUNIT_ASSERT( keyRing.size() == 0 );

  keyRing.insert("foo");
  CPPUNIT_ASSERT( keyRing.size() == 1 );
  CPPUNIT_ASSERT( *(keyRing.headers_.begin()) == "foo" );
  CPPUNIT_ASSERT( keyRing.headers_.size() == 1 );
  CPPUNIT_ASSERT( keyRing.headers2keys_.size() == 1 );
  CPPUNIT_ASSERT( keyRing[0] == "foo" );
  CPPUNIT_ASSERT( keyRing["foo"] == 0 );

  keyRing.insert("foo");
  CPPUNIT_ASSERT( keyRing.size() == 1 );
  CPPUNIT_ASSERT( *(keyRing.headers_.begin()) == "foo" );
  CPPUNIT_ASSERT( keyRing.headers_.size() == 1 );
  CPPUNIT_ASSERT( keyRing.headers2keys_.size() == 1 );
  CPPUNIT_ASSERT( keyRing[0] == "foo" );
  CPPUNIT_ASSERT( keyRing["foo"] == 0 );

  keyRing.insert("bar");
  CPPUNIT_ASSERT( keyRing.size() == 2 );
  CPPUNIT_ASSERT( keyRing.headers_.size() == 2 );
  CPPUNIT_ASSERT( keyRing.headers2keys_.size() == 2 );
  CPPUNIT_ASSERT( keyRing[0] == "foo" );
  CPPUNIT_ASSERT( keyRing[1] == "bar" );
  CPPUNIT_ASSERT( keyRing["foo"] == 0 );
  CPPUNIT_ASSERT( keyRing["bar"] == 1 );


  keyRing.insert("foo");
  CPPUNIT_ASSERT( keyRing.size() == 2 );
  CPPUNIT_ASSERT( keyRing.headers_.size() == 2 );
  CPPUNIT_ASSERT( keyRing.headers2keys_.size() == 2 );
  CPPUNIT_ASSERT( keyRing[0] == "foo" );
  CPPUNIT_ASSERT( keyRing[1] == "bar" );
  CPPUNIT_ASSERT( keyRing["foo"] == 0 );
  CPPUNIT_ASSERT( keyRing["bar"] == 1 );
  
  //CPPUNIT_ASSERT( keyRing)

}

// Registers the fixture into the test 'registry'
CPPUNIT_TEST_SUITE_REGISTRATION( KeyRingTest ); 

#endif // KEYRINGTEST_HPP
